import java.util.Scanner;

public class test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        String t = in.next();
        System.out.println(backspaceCompare(s,t));
    }
    public static boolean backspaceCompare(String s, String t) {
        StringBuilder s1 = new StringBuilder();
        StringBuilder s2 = new StringBuilder();
        //先处理第一个
        for (int i = 0; i < s.length(); i++) {
            if(s1.isEmpty()&&s.charAt(i)!='#'){
                s1.append(s.charAt(i));
                continue;
            }
            if(s.charAt(i)=='#'){
                if(s1.isEmpty()){
                    continue;
                }else s1.deleteCharAt(s1.length()-1);
            }else{
                s1.append(s.charAt(i));
            }
        }
        //处理第二个
        for (int i = 0; i < t.length(); i++) {
            if(s2.isEmpty()&&t.charAt(i)!='#'){
                s2.append(t.charAt(i));
                continue;
            }
            if(t.charAt(i)=='#'){
                if(s2.isEmpty()){
                    continue;
                }else s2.deleteCharAt(s2.length()-1);
            }else{
                s2.append(t.charAt(i));
            }
        }
        if (s1.compareTo(s2) == 0){
            return true;
        }
        return false;
    }
}
